﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using QS.Input;
using Microsoft.Xna.Framework.Input;
using QS.Logic.Objects;
using Microsoft.Xna.Framework.Graphics;
using QS.Drawables;
using QS.Game.Logic.Objects.common;

namespace QS.Game.Logic.Physics
{
    class QSpaceShipControl2D : QAbstractForce
    {
        public QSpaceShipControl2D( QPhysicsObject physicsObject)
            : base(physicsObject)
        {
        }

        protected override void updateForce()
        {
            List<Keys> keys = QKeyboardOperations.KeysDown;
            if (keys.Contains(Keys.W))
            {
                PhysicsObject.Force += Vector3.Transform(Vector3.Forward / 10000, this.PhysicsObject.Orientation);
                keys.Remove(Keys.W);
                ((QSpaceShip)this.PhysicsObject).EgnineIsOn = true;
            }
            else
                ((QSpaceShip)this.PhysicsObject).EgnineIsOn = false;

            if (keys.Contains(Keys.S))
            {
                PhysicsObject.Force += Vector3.Transform(Vector3.Backward / 10000, this.PhysicsObject.Orientation);
                keys.Remove(Keys.S);
            }

            if (keys.Contains(Keys.A))
            {
                this.PhysicsObject.Orientation *= Matrix.CreateRotationY(MathHelper.ToRadians(5f));
                keys.Remove(Keys.A);
            }

            if (keys.Contains(Keys.D))
            {
                this.PhysicsObject.Orientation *= Matrix.CreateRotationY(MathHelper.ToRadians(-5f));
                keys.Remove(Keys.D);
            }
        }
    }
}
